package com.derive.education_service.web.content.controller;

import com.derive.education_service.common.global.ResponseMessage;
import com.derive.education_service.web.content.service.ContentResService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("contentRes")
@Slf4j
public class ContentResController {

    @Autowired
    private ContentResService contentResService;

    /**
     * 添加内容->资源 -- 多文件上传
     * @param files
     * @param contentId
     * @return
     */
    @PostMapping("addContentRes")
    public ResponseMessage addContentRes(@RequestPart("files") List<MultipartFile> files,
                                         @RequestPart("contentId") @NotNull(message = "contentId不能为空") int contentId) {
        return contentResService.addContentRes(files, contentId);
    }

    /**
     * 删除内容->资源 -- 删除文件
     * @param crId
     * @return
     */
    @PostMapping("delContentRes")
    public ResponseMessage delContentRes(@NotNull(message = "crId不能为空") int crId) {
        return contentResService.delContentRes(crId);
    }

    /**
     * 更改内容资源信息 -- 更新之前先删除原先的资源信息
     * @param file
     * @param crId
     * @return
     */
    @PostMapping("upContentRes")
    public ResponseMessage upContentRes(@RequestPart("file") MultipartFile file,
                                        @NotNull(message = "crId不能为空") @RequestPart("crId") int crId) {
        return contentResService.upContentRes(file, crId);
    }

    /**
     * 查询内容下的资源 -- 不分页 -- 只有资源信息
     * @param contentId
     * @return
     */
    @GetMapping("getContentResList")
    public ResponseMessage getContentResList(@NotNull(message = "contentId不能为空") int contentId) {
        return contentResService.getContentResList(contentId);
    }
}
